package com.wondersgroup.fjzlpt.tbxt.dao.impl.gyzjb;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.repository.sql.bean.page.PageQuerySQLBean;
import com.quick.framework.boot.repository.sql.bean.table.TableBean;
import com.quick.framework.boot.repository.sql.jdbcTemplate.impl.BaseJTDAOImpl;
import com.quick.framework.boot.repository.sql.jdbcTemplate.rs.ResultHandlerConstant;
import com.quick.framework.util.FormatDate;
import com.wondersgroup.fjzlpt.tbxt.dao.inter.gyzjb.ShjlDao;

@Repository
public class ShjlDaoImpl extends BaseJTDAOImpl implements ShjlDao {

	@Override
	@Autowired
	@Qualifier("TB_TBXT_SHJL")
	public void setTb(TableBean tb) {
		super.setTb(tb);
	}

	@Override
	public void insert(Map map) {
		map.put("BBID", map.remove("ID"));  //报表ID
		map.put("ID", UUID.randomUUID().toString()); //审核ID
		map.put("SHSJ", new Date());
		map.put("SHJG", map.remove("ZT"));  //审核结果
		super.insert(map);
	}

	@Override
	public JSONObject queryShjlByPage(Map<String, String> map) {
		StringBuffer sqlBuf = new StringBuffer();
		sqlBuf.append("select * from ").append(this.tb.getTableName()).append(" where 1=1 ");
		
		List<String> sqlParams = new ArrayList<String>();
		String value = map.get("BBID");
		if(!StringUtils.isEmpty(value)){
			sqlBuf.append("and BBID = ?");
			sqlParams.add(value);
		}
		
		PageQuerySQLBean pageBean = super.checkAndCreatePageQuerySQLBean(map, sqlBuf.toString(), "order by SHSJ desc", sqlParams.toArray());
		return super.queryPage(pageBean, ResultHandlerConstant.JSONARRAY);
	}

}
